package book.test03;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class JavaBean implements WritableComparable<JavaBean> {
    private String city;
    private String companyName;
    private int count;

    @Override
    public int compareTo(JavaBean o) {
        if (this.getCity().compareTo(o.getCity()) == 0)
            return o.count - this.count;
        return this.getCity().compareTo(o.getCity());
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(city);
        dataOutput.writeUTF(companyName);
        dataOutput.writeInt(count);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.city = dataInput.readUTF();
        this.companyName = dataInput.readUTF();
        this.count = dataInput.readInt();
    }

    @Override
    public String toString() {
        return city + "\t" +
                companyName + "\t" +
                count;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
